﻿function refresh() {
    location.href = "/admin/"+URLS+"/index";
}

function add(id) {
    if (id) {
        location.href = "/admin/" + URLS + "/Create/" + id;
    } else {
        location.href = "/admin/" + URLS + "/Create/";
    }
}

function cache() {
    location.href = "/admin/" + URLS + "/Cache";
}

function edit(id) {
    var keyValue;
    if (id) {
        keyValue = id;
    } else {
        keyValue = getSelectCheckboxValue();
    }
    if (!keyValue) {
        alert('请选择编辑项！');
        return false;
    }
    location.href = "/admin/" + URLS + "/edit/" + keyValue;
}

var selectRowIndex = Array();

function delMore() {

    var keyValue;
    keyValue = getSelectCheckboxValues();
    if (!keyValue) {
        alert('请选择删除项！');
        return false;
    }

    if (window.confirm('确实要删除选择项吗？')) {
        location.href = "/admin/" + URLS + "/deletes/" + keyValue;
    }
}

function del(id) {
    var keyValue;
    if (id) {
        keyValue = id;
    } else {
        keyValue = getSelectCheckboxValues();
    }
    if (!keyValue) {
        alert('请选择删除项！');
        return false;
    }

    if (window.confirm('确实要删除选择项吗？')) {
        location.href = "/admin/" + URLS + "/delete/" + keyValue;
    }
}

function getSelectCheckboxValue() {
    var obj = document.getElementsByName('key');
    var result = '';
    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked == true)
            return obj[i].value;

    }
    return false;
}

function getSelectCheckboxValues() {
    var obj = document.getElementsByName('key');
    var result = '';
    var j = 0;
    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked == true) {
            selectRowIndex[j] = i + 1;
            result += obj[i].value + ",";
            j++;
        }
    }
    return result.substring(0, result.length - 1);
}

function change(e) {
    if (!document.all) {
        return;
    }
    var e = e || event;
    var oObj = e.srcElement || e.target;
    //if(oObj.tagName.toLowerCase()   ==   "td")   
    // {   
    /*
    var   oTable   =   oObj.parentNode.parentNode;   
    for(var   i=1;   i<oTable.rows.length;   i++)   
    {   
    oTable.rows[i].className   =   "out";   
    oTable.rows[i].tag   =   false;   
    }   */
    var obj = document.getElementById('gvList').getElementsByTagName("input");
    var oTr = oObj.parentNode;
    var row = oObj.parentElement.rowIndex;
    if (oTr.className == 'down') {
        oTr.className = 'out';
        obj[row].checked = false;
        oTr.tag = true;
    } else {
        oTr.className = 'down';
        obj[row].checked = true;
        oTr.tag = true;
    }
    //}   
}

function out(e) {
    var e = e || event;
    var oObj = e.srcElement || e.target;
    var oTr = oObj.parentNode;
    if (!oTr.tag)
        oTr.className = "out";
}

function over(e) {
    var e = e || event;
    var oObj = e.srcElement || e.target;
    var oTr = oObj.parentNode;
    if (!oTr.tag)
        oTr.className = "over";

}

//选择所有项
function CheckAll(strSection) {
    var i;
    var colInputs = document.getElementById(strSection).getElementsByTagName("input");
    for (i = 1; i < colInputs.length; i++) {
        colInputs[i].checked = colInputs[0].checked;
    }
}

//上传图片
function swfupload(url, returnImg, returnInput, folder) {
    art.dialog.data('imgurl', document.getElementById(returnInput).value); //传输图片路径
    art.dialog.open(url, {
        title: '图片上传',
        init: function () {
            var iframe = this.iframe.contentWindow;
            iframe.document.getElementById('imgshow').src = art.dialog.data('imgurl');
            iframe.document.getElementById('oldimageurl').value = art.dialog.data('imgurl');
            iframe.document.getElementById('id').value = folder;
        },
        lock: true,
        cancel: true,
        ok: function () {
            var returnValue = art.dialog.data('returnValue');
            if (returnValue != undefined) {
                document.getElementById(returnImg).src = returnValue;
                document.getElementById(returnInput).value = returnValue;
            }
        }
    });
}


//设置默认图片
function SetDefaultPhoto(url) {
    document.getElementById("ImageUrl").value = url;
}

//删除显示的图片
function DeleteShowImg(url) {
    var node = document.getElementById(url);
    node.parentNode.removeChild(node);
    var str = url + ",";
    var oldstr = document.getElementById("AddPhoto").value;
    var newstr = oldstr.replace(str, "");
    document.getElementById("AddPhoto").value = newstr;
    document.getElementById("DelPhoto").value = document.getElementById("DelPhoto").value + url + ",";
}

//上传产品
function uploadpruduct(url, returnInput, folder,showid) {

    art.dialog.open(url, {
        title: '产品上传',
        init: function () {
            var iframe = this.iframe.contentWindow;
            iframe.document.getElementById('id').value = folder;
        },
        lock: true,
        cancel: true,
        ok: function () {
            var returnValue = art.dialog.data('returnValue');
            if (returnValue != undefined) {
                var img = '<ul id="' + returnValue + '"><i><img height="150" width="150" src="' + returnValue + '" /></li><li><a onclick="DeleteShowImg(\'' + returnValue + '\')">删除</a>&nbsp;&nbsp;&nbsp;<input onclick="SetDefaultPhoto(\'' + returnValue + '\')" name="default" type="radio" /></li></ul>';
                document.getElementById(showid).innerHTML = document.getElementById(showid).innerHTML+img;
                document.getElementById(returnInput).value = document.getElementById(returnInput).value + returnValue + ",";
            }
        }
    });
}